<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title><fmt:message code="document.th.nextStep" /></title>
    <link rel="stylesheet" href="/css/workflow/work/m/style.css">
    <style>
        /*.bag{background: url(ui/img/widget_check.png)no-repeat -5px -5px;}*/
        /*.bag{*/
            /*background: url(../../../ui/img/widget_check1.png)no-repeat 0 0;*/
        /*}*/
    </style>
</head>
<body>
<button id="turnBtn" style="display: none;"><fmt:message code="workflow.th.Transfer" /></button>
<div class="turnview" id="pro_turn"><div class="word_title">
    <img src="/img/workflow/m/apply_next_select.png" alt="" class="icon">
    <div class="word_quick_action"><fmt:message code="main.th.nextStep" /></div>
</div>
    <div class="list-panel" id="nextstep">

    </div>

    <div id="panel-next-user">
        <div class="word_title nofirest">
            <img src="/img/workflow/m/apply_next_select.png" alt="" class="icon">
            <div class="word_quick_action"><fmt:message code="workflow.th.nextStepStaff" /></div>
        </div>

        <div class="main" style="position:inherit;">
            <div class="main2" id="prcsUserlist" style="margin-top:0px;">
                <%--<div class="all_select">--%>
                <%--<div class="main_2">--%>
                <%--<div class="l"><div uname="" uid="101006686" class="circle bag"></div></div>--%>
                <%--<div class="r"><h1>丹丹</h1></div>--%>
                <%--</div>--%>
                <%--</div>--%>

                <%--<div class="all_select" >--%>
                <%--<div class="main_2">--%>
                <%--<div class="l"><div uname="" uid="101000152" class="circle"></div></div>--%>
                <%--<div class="r"><h1>高然</h1></div>--%>
                <%--</div>--%>
                <%--</div>--%>
            </div>
        </div>
    </div>
    <div class="word_title nofirest">
        <img src="/img/workflow/m/apply_next_select.png" alt="" class="icon">
        <div class="word_quick_action"><fmt:message code="workflow.th.NotificationRange" /></div>
    </div>
    <div class="list-panel">
        <ul class="list-group next_steps">
            <li class="list-group-item" style="display: none;"><input type="checkbox" value="1" name="notice_prev_user"><fmt:message code="workflow.th.PreviousApplicationPersonnel" /></li>
            <li class="list-group-item"><input type="checkbox" value="1" name="notice_next_user" checked=""><fmt:message code="workflow.th.NextStaff" /></li>
            <li class="list-group-item"><input type="checkbox" value="1" name="notice_apply_user"><fmt:message code="workflow.th.firstApplyPersonnel" /></li>
            <li class="list-group-item"><input type="checkbox" value="1" name="notice_all_user"><fmt:message code="workflow.th.AllPersonnel" /></li>
        </ul>
    </div>
</div>
<script src="/js/jquery/jquery-1.9.1.js"></script>
<script src="/js/base/base.js"></script>
<script src="/lib/laydate/laydate.js"></script>
<script src="/js/mustache.min.js"></script>
<script src="/js/template.js"></script>
<script>

    $.extend({
        getQueryString:function(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
            var r = window.location.search.substr(1).match(reg);
            if (r != null) return unescape(r[2]);
            return null;
        }
    });
    var globalData = {};
    var flowId = $.getQueryString("flowId");
    var flowStep = $.getQueryString("flowStep") || '';
    var prcsId = $.getQueryString("prcsId") || '';
    var runId = $.getQueryString("runId") || '';
    var tabId = $.getQueryString("tabId") || '';
//    alert(prcsId)
    function buildUserByNextPrcId(nextPrcsId){
        $.ajax({
            type: "get",
            url: "/street/workflow/work/findbranch",
            dataType: 'JSON',
            data: {
                flowId:flowId,
                flowPrcs:nextPrcsId,
                runId:runId
            },
            success: function (res) {
                if(res.flag){
                    var userList = '';
                    if(res.object && res.object.prcsUserlist){
                        res.object.prcsUserlist.forEach(function (v,i) {
                            userList += '<div class="all_select"><div class="main_2"> <div class="l"><div uname="" uid="'+v.uid+'" userId="'+v.userId+'" class="circle"></div></div><div class="r"><h1>'+v.userName+'&nbsp;'+v.userPrivName+'</h1></div></div></div>'
                        });
                        $('#prcsUserlist').html(userList);
                    }


                }
            }
        });
    };
    var turn;
    <%--function ready(){--%>
        <%--Android.rightTitle('<fmt:message code="workflow.th.Transfer" />','xxxxx','turn');--%>
    <%--}--%>
    $(function () {

        $.ajax({
            type: "get",
            url: '/street/workflow/work/workfastAdd',
            dataType: 'JSON',
            data: {
                flowId:flowId,
                runId:runId,
                prcsId:prcsId,
                flowStep:flowStep,
            },
            success: function (res) {
                console.log(res);
                if(res.flag){
                    globalData.listFp = res.object.listFp;
                    globalData.flowRun = res.object.flowRun;
                    buildNextStep(globalData.listFp,prcsId);
                }
            }
        });
        function buildNextStep(arr,prcsId){
            var listFp = {}
            arr.forEach(function(v,i){
                listFp[v.prcsId] = v;
            })
            var prcName = '';
            var nextPrcsArr = listFp[prcsId].prcsTo;
            if(nextPrcsArr.indexOf(',')){
                nextPrcsArr = nextPrcsArr.split(',');
            }
            nextPrcsArr.forEach(function (v,i) {
                if(v){
                    var checked = 'checked="checked"';
                    if(v == 0){
                        prcName +='<span class="nofirest"><input type="radio" nextPrcsId="0" value="normal2" name="nextstep" ><fmt:message code="workflow.th.EndingApproval" /></span>';
                    }else{
                        var prc = listFp[v];
                        prcName +='<span class="nofirest"><input type="radio" nextPrcsId="'+prc.prcsId+'" value="normal2" name="nextstep" >'+prc.prcsName+'</span>';
                    }
                }
            });
            $('#nextstep').html(prcName);
            var firstNextPrc =  $('#nextstep').find('input').eq(0);
            var nextPrcsId = firstNextPrc.attr('nextPrcsId');
            firstNextPrc.prop('checked','checked');
            buildUserByNextPrcId(nextPrcsId);

        };

        turn = function() {

            var savedData ={
                flowId:flowId,
                runId:runId,
                runName:globalData.flowRun.runName,
                beginTime:globalData.flowRun.beginTime,
                beginUser:$('#prcsUserlist .bag').eq(0).attr('userid'),
                prcsId:flowStep,
                prcsflag:1,
                tabId:tabId,
                flowPrcs:$('#nextstep input[name="nextstep"]:checked').eq(0).attr('nextprcsid'),
                jingbanUser:$('#prcsUserlist .bag').eq(0).attr('userid')||''
            };

            $.ajax({
                type: "post",
                url: "/street/workflow/work/saveWork",
                dataType: 'JSON',
                data: savedData,
                success: function (obj) {
                    if(obj.flag){
                        <%--alert("<fmt:message code="workflow.th.DeliverSuccessfully" />！");--%>
                        if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                            try{
                                window.webkit.messageHandlers.finishWork.postMessage({});
                            }catch(err){
                                finishWork();
                            }
                        } else if (/(Android)/i.test(navigator.userAgent)) {
                            //alert(navigator.userAgent);
                            Android.finishWebActivity();
                        }
                    }
                }
            });
        };
        $('#turnBtn').click(function () {
            turn();
        })
        $(".main2").on("click",'.all_select',function(){
            $(".main2 .bag").removeClass('bag');
            $(this).find('.circle').addClass('bag');
        });

    });

    var array = [];
    array['normal'] = [{'uid':'101006686','name':'丹丹'},{'uid':'101000152','name':'高然'}];
    array['normal1'] = [{'uid':'101006666','name':'林丹丹'},{'uid':'101000152','name':'刘建彩'}];
    array['normal2'] = [{'uid':'101006677','name':'林丹'},{'uid':'101000152','name':'张明'},{'uid':'101000156','name':'李明'}];
    $(document).on('click','.nofirest input',function(){
        console.log($(this).val());
        var val = $(this).attr('nextprcsid');
        buildUserByNextPrcId(val);
    });
    function ajax_info(val){

    };
    console.log(array);
    ajax_info($('input:radio:checked').val());
</script>
</body>
</html>